package com.os.config;


import com.os.constant.Mq;
import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 风亦未止
 * @date 2023/5/5 23:11
 */
@Configuration
public class MqConfig {

    /**
     * 序列化
     *
     * @return
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    public MessagePostProcessor  messagePostProcessor(){
        return message -> {
            //回复的消息的临时队列名
            message.getMessageProperties().setReplyTo(Mq.TEMP_QUEUE);
            message.getMessageProperties().setExpiration(String.valueOf(3000));
            return message;
        };
    }

    /**
     * 接收数据定位后的发送的队列
     * @return
     */
    @Bean("tempQueue")
    public Queue tempQueue(){
        return QueueBuilder.durable(Mq.TEMP_QUEUE).build();
    }

}
